Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default arguments ability and update tests. #91

Merged
merged 16 commits into from
Sep 18, 2018

Conversation

T-Nicholls
Copy link
Collaborator

@T-Nicholls T-Nicholls commented Sep 14, 2018

Changes made - ready to merge again.
I also added tests for the template classes Device and DataSource, as ControlSystem already had them.
So I have renamed test_cs to test_invalid_classes, all that it does is checks all methods on all the template classes raise NotImplementedError.

@coveralls
Copy link

coveralls commented Sep 14, 2018

Coverage Status

Coverage increased (+1.2%) to 99.416% when pulling be0d930 on T-Nicholls:addDefault into f30a5a3 on dls-controls:master.

@T-Nicholls
Copy link
Collaborator Author

T-Nicholls commented Sep 14, 2018

After looking into control systems, I am not sure that CothreadControlSystem should inherit from the template class ControlSystem. I believe it should inherit from object and just use ControlSystem as a guide like the device classes and Device, and data sources and DataSource. Am I right or is there a reason for the inconsistency? All device, data source and control system classes now inherit from their base not implemented class correctly.

@willrogers
Copy link
Collaborator

Having thought about it, I don't think that it is sensible to have a default 'handle'. It makes sense to want to work in engineering or physics units, or to work with the sim or live, but not to work with 'setpoint' all the time.

I suggest we remove that aspect from the pull request.

ENG = 'engineering'
PHYS = 'physics'
# Data Source types.
SIM = 'simulation'
LIVE = 'live'
# Default argument flag.
default = 'default'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a constant so should be in all caps i.e.

DEFAULT = 'default'

@T-Nicholls
Copy link
Collaborator Author

Ok I will remove default handle and put it back to how it was with get_value using pytac.RB as the default specified argument and set_value using pytac.SP.
I'll also fix the capitalisation of pytac.DEFAULT.

units = self._default_units
if data_source is pytac.default:
if data_source is pytac.DEFAULT:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should really use == not is in this case. I think it's unlikely to cause you a problem, but there's a chance that you end up with a string default that won't compare correctly as DEFAULT.

https://stackoverflow.com/questions/1504717/why-does-comparing-strings-in-python-using-either-or-is-sometimes-produce

Copy link
Collaborator Author

@T-Nicholls T-Nicholls Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That stack overflow makes sense, interestingly I currently can't cause that problem in our code, but I will change it just in case.

pytac/lattice.py Outdated
element.set_value(field, value)
element.set_value(field, value, handle=pytac.SP)

def set_default_arguments(self, default_units=None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now looks a bit strange for this to be one method - I suggest you split it into two.

pytac/lattice.py Outdated
raise LatticeException('Please set at least one default argument '
'for units or data_source.')
if default_units == pytac.ENG or default_units == pytac.PHYS:
self._data_source_manager._default_units = default_units
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using a private attribute _default_units from outside the DataSourceManager class. Should it be a public attribute?

pytac/lattice.py Outdated
return self._data_source_manager.default_units

def get_default_data_source(self):
"""Get the default data source, pytac.RB or pytac.SP.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment wrong.

pytac/lattice.py Outdated
pytac.LIVE, pytac.SIM))

def get_default_units(self):
"""Get the default unit type, pytac.RB or pytac.SP.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment wrong.

@willrogers
Copy link
Collaborator

I'm finding it quite hard to think through all the consequences of these changes. I've made a couple of comments about the docstrings, then I'll merge and we'll see how we get on.

@T-Nicholls
Copy link
Collaborator Author

Fixed those two mistakes. I'm not sure if there are many consequences, as pytac will function as it does currently if the defaults are not changed and I don't think there are any complications when defaults are set as the use cases are pretty limited.

@willrogers willrogers merged commit a38a5e8 into DiamondLightSource:master Sep 18, 2018
@T-Nicholls T-Nicholls deleted the addDefault branch October 4, 2018 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants